<?php

namespace App\Console\Commands\Fee;

use App\Models\Fee\FeeAnnualOrderModel;
use Illuminate\Console\Command;

class AddFeeEndTime extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'fee:add-fee-end-time';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '延长到期的年费订单';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        // 延长15天
        $endTime = strtotime(date('Ymd')) + 86400 * 15;

        FeeAnnualOrderModel::query()
                           ->where('payStatus', '!=', FeeAnnualOrderModel::PAY_STATUS_OK)
                           ->where('endTime', '<=', $endTime)
                           ->get()
                           ->each(function ($item) use ($endTime) {
                               $this->info("shopId:{$item->shopId} endTime:" . date('Y-m-d H:i:s', $item->endTime));

                               $item->endTime = $endTime;
                               $item->save();
                           });
    }
}
